package com.ease.context.datastructure;

import com.ease.common.util.Detect;

/**
 * http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern
 * 
 * @author nathanleewei
 * 
 * @param <T>
 */
public abstract class ChainOfResponsibilityNode<T /* context */> extends Detect {

	protected ChainOfResponsibilityNode<T> successor;

	public abstract void process(T context);

	public void turnOver(T context) {
		if (null != successor) {
			successor.process(context);
		}
	}

	/**
	 * @param successor
	 *            the successor to set
	 */
	public void setSuccessor(ChainOfResponsibilityNode<T> successor) {
		this.successor = successor;
	}
}
